home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / _OPEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  642 b   |  27 lines

  1. /* _OPEN.C --- p. 643 */
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <dos.h>
  5. #include <io.h>
  6. main()
  7. {
  8.     char fname[40], *p_fname;
  9.     int filehandle;
  10.     printf("Enter name of file to open using _open: ");
  11.     p_fname = gets(fname);
  12.             /* Open the file in "DENY ALL" mode and for reading
  13.              * only */
  14.     if((filehandle = _open(p_fname, O_DENYALL | O_RDONLY)) == -1)
  15.     {
  16.         printf("Error opening file: %s\n", fname);
  17.         exit(0);
  18.     }
  19.     printf("File %s opened.\n", fname);
  20.                         /* Now close file */
  21.     if(_close(filehandle) == -1)
  22.     {
  23.         printf("Error closing file with _close\n");
  24.         exit(0);
  25.     }
  26.     printf("File %s closed.\n", fname);
  27. }